import { fileURLToPath, URL } from 'node:url'
import requireTransform from 'vite-plugin-require-transform';
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars';

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'node:path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  "server": {
    "proxy": {
      '/api': {
        "target": "http://localhost:18000",
        "rewrite": (path) => {
          return path.replace(/^\/api/, '');
        }
      },
    }
  },
  devServer: {
  },
  plugins: [
    vue(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      "~bootstrap": path.resolve(__dirname, './node_modules/bootstrap')
    },
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
      requireTransform({ fileRegex: /.js$|.vue$/ }),
      dynamicImportVars({
        "include": "extends"
      })
    ]
  }
})
